package com.hx.hospital.mapper;

import com.hx.hospital.pojo.Doctor;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface DoctorMapper extends Mapper<Doctor> {

    @Results(id = "DoctorResult",value = {
            @Result(property = "id",column = "id",jdbcType = JdbcType.BIGINT),
            @Result(property = "name",column = "name",jdbcType = JdbcType.VARCHAR),
            @Result(property = "departmentId",column = "department_id",jdbcType = JdbcType.VARCHAR),
            @Result(property = "departmentName",column = "department_name",jdbcType = JdbcType.VARCHAR),
            @Result(property = "sex",column = "sex",jdbcType = JdbcType.BIGINT),
            @Result(property = "positionId",column = "position_id",jdbcType = JdbcType.BIGINT),
            @Result(property = "position",column = "position",jdbcType = JdbcType.VARCHAR),
            @Result(property = "IndicationsId",column = "Indications_id",jdbcType = JdbcType.BIGINT),
            @Result(property = "Indications",column = "Indications",jdbcType = JdbcType.VARCHAR),
            @Result(property = "doctorPhoto",column = "doctor_photo",jdbcType = JdbcType.VARCHAR),
            @Result(property = "enableStatus",column = "enable_status",jdbcType = JdbcType.VARCHAR),
            @Result(property = "describe",column = "describe",jdbcType = JdbcType.VARCHAR),
            @Result(property = "detailedDepartmentsId",column = "detailed_departments_id",jdbcType = JdbcType.BIGINT),
            @Result(property = "detailedDepartmentName",column = "detailed_department_name",jdbcType = JdbcType.VARCHAR)
    })
    @Select("SELECT\n" +
            "d.id,\n" +
            "d.`name`,\n" +
            "d.sex,\n" +
            "d.doctor_photo,\n" +
            "d.enable_status,\n" +
            "d.`describe`,\n" +
            "dp.position,\n" +
            "di.Indications,\n" +
            "dd.detailed_department_name,\n" +
            "d.position_id,\n" +
            "d.Indications_id,\n" +
            "d.department_id\n" +
            "FROM\n" +
            "doctor AS d\n" +
            "LEFT JOIN doctor_Indications AS di ON d.Indications_id = di.id\n" +
            "LEFT JOIN doctor_position AS dp ON d.position_id = dp.id\n" +
            "LEFT JOIN detailed_departments AS dd ON d.department_id = dd.id\n" +
            "WHERE\n" +
            "d.id is not null\n")
    public List<Doctor> findDoctorAll();



    @ResultMap("DoctorResult")
    @Select("SELECT\n" +
            "d.id,\n" +
            "d.`name`,\n" +
            "d.sex,\n" +
            "d.doctor_photo,\n" +
            "d.enable_status,\n" +
            "d.`describe`,\n" +
            "dp.position,\n" +
            "di.Indications,\n" +
            "dd.detailed_department_name,\n" +
            "d.position_id,\n" +
            "d.Indications_id,\n" +
            "d.department_id\n" +
            "FROM\n" +
            "doctor AS d\n" +
            "LEFT JOIN doctor_Indications AS di ON d.Indications_id = di.id\n" +
            "LEFT JOIN doctor_position AS dp ON d.position_id = dp.id\n" +
            "LEFT JOIN detailed_departments AS dd ON d.department_id = dd.id\n" +
            "WHERE\n" +
            "d.id = #{id}\n")
    public List<Doctor> findDoctorById(@Param("id") Long id);


}
